import * as z from 'zod';
import type { FormSchema } from '../types';

// 部门表单 Schema
export const departmentFormSchema: FormSchema = {
  config: {
    fields: [
      {
        name: 'name',
        type: 'text',
        label: '部门名称',
        placeholder: '请输入部门名称',
        required: true,
        grid: { cols: 1 },
      },
      {
        name: 'code',
        type: 'text',
        label: '部门编码',
        placeholder: '请输入部门编码',
        required: true,
        grid: { cols: 1 },
        helpText: '部门编码用于系统内部标识，建议使用英文和数字',
      },
      {
        name: 'description',
        type: 'textarea',
        label: '部门描述',
        placeholder: '请输入部门描述（可选）',
        grid: { span: 2 },
      },
    ],
    layout: {
      columns: 2,
      spacing: 'space-y-4',
    },
  },
  validationSchema: z.object({
    name: z.string().min(1, '部门名称不能为空').max(50, '部门名称不能超过50个字符'),
    code: z.string().min(1, '部门编码不能为空').max(20, '部门编码不能超过20个字符'),
    description: z.string().optional(),
  }),
  initialValues: {
    name: '',
    code: '',
    description: '',
  },
};

// 创建部门表单 Schema
export const createDepartmentFormSchema: FormSchema = {
  ...departmentFormSchema,
};

// 编辑部门表单 Schema
export const editDepartmentFormSchema: FormSchema = {
  ...departmentFormSchema,
  validationSchema: z.object({
    id: z.string().min(1, '部门ID不能为空'),
    name: z.string().min(1, '部门名称不能为空').max(50, '部门名称不能超过50个字符'),
    code: z.string().min(1, '部门编码不能为空').max(20, '部门编码不能超过20个字符'),
    description: z.string().optional(),
  }),
};
